﻿using System;
using FaceRecognitionDemo.Data;
using FaceRecognitionDemo.Services;

class Program
{
    private static FaceRecognitionService service = new FaceRecognitionService(new FaceDatabase());

    static async Task initSample()
    {
        Console.WriteLine("1. 录入人脸样本");
        var name = "习近平";
        var sampleFolder = @"D:\other\test\trae\ViewFaceCore\FaceRecognitionDemo\sample\xijinping";

        // 添加人员
        var peron = await service.AddPerson(name);

        // 遍历文件夹添加样本
        var imageFiles = Directory.GetFiles(sampleFolder);
        foreach (var imagePath in imageFiles)
        {
            try
            {
                await service.AddFaceToPerson(peron.Id, imagePath);
                Console.WriteLine($"成功添加样本: {Path.GetFileName(imagePath)}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"添加样本失败: {ex.Message}");
            }
        }
    }

    static async Task Main(string[] args)
    {
       // initSample();
        
        var name = "习近平";
        
        while (true)
        {
            try
            {
                Console.WriteLine("\n2. 人脸比对测试");
                Console.Write("请输入测试图片路径: ");
                var testImage = @"D:\other\test\trae\ViewFaceCore\FaceRecognitionDemo\compare\" + Console.ReadLine()+".jpg";

                var results = await service.CompareFaces(name, testImage);
                foreach (var result in results)
                {
                    Console.WriteLine($"相似度: {result.SimilarityScore:P}");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}